package com.xd.springboot.service.impl;

import com.xd.springboot.entity.User;
import com.xd.springboot.event.MyEvent;
import com.xd.springboot.service.UserService;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class UserServiceImpl implements UserService {

    @Resource
    private ApplicationContext applicationContext;

    @Override
    public User getUser() {
        User user=new User(131L,"测试","123456");
        //发布事件,发布之后，自定义监听器就可以监听到
        MyEvent myEvent=new MyEvent(this,user);
        applicationContext.publishEvent(myEvent);
        return user;
    }
}
